<?php

/**
 * This is the model class for table "{{thread}}".
 *
 * The followings are the available columns in table '{{thread}}':
 * @property integer $ID
 * @property string $question
 * @property string $answer
 * @property integer $issueID
 * @property integer $createddate
 * @property integer $modifieddate
 * @property integer $status
 * @property string $comment
 * @property integer $editor1
 * @property integer $editor2
 * @property integer $answerID
 */
class Thread extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Thread the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{thread}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			//array('question, answer, issueID, createddate, modifieddate, status, comment, editor1, editor2, answerID', 'required'),
			array('issueID, status', 'required'),
			array('issueID, createddate, modifieddate, status, editor,resolver, answerID', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID, question, answer, issueID, createddate, modifieddate, status, comment, editor, resolver, answerID', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID' => 'ID',
			'question' => 'Question',
			'answer' => 'Answer',
			'issueID' => 'Issue',
			'createddate' => 'Createddate',
			'modifieddate' => 'Modifieddate',
			'status' => 'Status',
			'comment' => 'Comment',
			'editor' => 'Editor',
			'resolver' => 'Resolver',
			'answerID' => 'Answer',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID',$this->ID);
		$criteria->compare('question',$this->question,true);
		$criteria->compare('answer',$this->answer,true);
		$criteria->compare('issueID',$this->issueID);
		$criteria->compare('createddate',$this->createddate);
		$criteria->compare('modifieddate',$this->modifieddate);
		$criteria->compare('status',$this->status);
		$criteria->compare('comment',$this->comment,true);
		$criteria->compare('editor',$this->editor);
		$criteria->compare('resolver',$this->resolver);
		$criteria->compare('answerID',$this->answerID);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function getQuestions($issueID,$resolverID)
	{
		$array = array();
		$question = Thread::model()->findAllByAttributes(array('issueID'=>$issueID,'resolver'=>$resolverID));
		if (!empty($question))
    {
      foreach ($question as $r) {
        $array[$r['ID']] = $r['ID'];	       
      }
    }
    return $array;	
	}
	
}